/**
 * 
 */
package org.gigi.security.spring;

import org.gigi.security.domain.User;
import org.gigi.security.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * Spring Security 扩展。
 *
 * @author Eugene Wang 2011-11-11
 * @see
 */
public class GigiUserDetailsService implements UserDetailsService {
	@Autowired
	private UserService userService;
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = userService.findByUsername(username);
		if (user == null) {
			throw new UsernameNotFoundException("用户名["+username+"]不存在！");
		}
		UserDetails userDetails = new GigiUserDetails(user);
		return userDetails;
	}
}
